package com.zwh.modules.datamax.service;

import com.zwh.modules.datamax.entity.DataMax;
import org.flowable.engine.HistoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.task.api.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class FlowableService {
    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private TaskService taskService;
    @Autowired
    private DataMaxService dataMaxService;

    @Autowired
    private HistoryService historyService;


    /**
     * 启动流程
     * @param assignee
     */
    public void startProcess(String assignee) {


        Map<String, Object> variables = new HashMap<String, Object>();
        variables.put("dataMaxList", dataMaxService.findSimpleList(new DataMax()));
        runtimeService.startProcessInstanceByKey("holidayRequest", variables);
    }

    /**
     * 获取流程实例
     */
    public void getHistoryInst(){
        historyService.createHistoricProcessInstanceQuery().processInstanceId("id").singleResult();
    }

    /**
     * 获得流程任务
     * @param assignee
     * @return
     */
    public List<Task> getTasks(String assignee) {
        List<Task> taskList=  taskService.createTaskQuery().includeProcessVariables().list();
        taskList.get(0).getExecutionId();
        return taskList;
    }
}
